import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDLotteryBase {
	/**id*/
	id,
	/**抽奖类型Lottery.id--1.金币装备2.钻石装备3.宠物4.转盘*/
	lotteryType,
	/**免费次数*/
	freeTimes,
	/**每日限制次数buytimelimitid*/
	limitid,
	/**是需要看广告--1.看广告不消耗道具--0.消耗道具*/
	watchAd,
	/**排序*/
	order,
	/**等级*/
	level,
	/**解锁id*/
	unlockid,
	/**活动id*/
	activityID,
	/**最大序列数*/
	maxDropIndex,
	/**抽奖消耗道具类型*/
	costType,
	/**抽奖消耗道具*/
	costItem,
	/**抽奖消耗道具数量*/
	costNum,
	/**显示召唤类型--1.可以左右切换等级（装备)--2.不能切换等级(宠物)*/
	showType,
	/**名称*/
	name,
	/**描述*/
	desc,
	/**等级名称*/
	levelName,
	/**背景*/
	background,

	/**枚举数量*/
	EnumCount
}



export class CDLotteryBase{
	/**id*/
	public id: number;
	/**抽奖类型Lottery.id--1.金币装备2.钻石装备3.宠物4.转盘*/
	public lotteryType: number;
	/**免费次数*/
	public freeTimes: number;
	/**每日限制次数buytimelimitid*/
	public limitid: number;
	/**是需要看广告--1.看广告不消耗道具--0.消耗道具*/
	public watchAd: number;
	/**排序*/
	public order: number;
	/**等级*/
	public level: number;
	/**解锁id*/
	public unlockid: number;
	/**活动id*/
	public activityID: number;
	/**最大序列数*/
	public maxDropIndex: number;
	/**抽奖消耗道具类型*/
	public costType: number;
	/**抽奖消耗道具*/
	public costItem: number;
	/**抽奖消耗道具数量*/
	public costNum: number;
	/**显示召唤类型--1.可以左右切换等级（装备)--2.不能切换等级(宠物)*/
	public showType: number;
	/**名称*/
	public name: number;
	/**描述*/
	public desc: number;
	/**等级名称*/
	public levelName: number;
	/**背景*/
	public background: string;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDLotteryBase.id: return this.id;
			case E_CDLotteryBase.lotteryType: return this.lotteryType;
			case E_CDLotteryBase.freeTimes: return this.freeTimes;
			case E_CDLotteryBase.limitid: return this.limitid;
			case E_CDLotteryBase.watchAd: return this.watchAd;
			case E_CDLotteryBase.order: return this.order;
			case E_CDLotteryBase.level: return this.level;
			case E_CDLotteryBase.unlockid: return this.unlockid;
			case E_CDLotteryBase.activityID: return this.activityID;
			case E_CDLotteryBase.maxDropIndex: return this.maxDropIndex;
			case E_CDLotteryBase.costType: return this.costType;
			case E_CDLotteryBase.costItem: return this.costItem;
			case E_CDLotteryBase.costNum: return this.costNum;
			case E_CDLotteryBase.showType: return this.showType;
			case E_CDLotteryBase.name: return this.name;
			case E_CDLotteryBase.desc: return this.desc;
			case E_CDLotteryBase.levelName: return this.levelName;
			case E_CDLotteryBase.background: return this.background;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDLotteryBase.id: this.id = v; break;
			case E_CDLotteryBase.lotteryType: this.lotteryType = v; break;
			case E_CDLotteryBase.freeTimes: this.freeTimes = v; break;
			case E_CDLotteryBase.limitid: this.limitid = v; break;
			case E_CDLotteryBase.watchAd: this.watchAd = v; break;
			case E_CDLotteryBase.order: this.order = v; break;
			case E_CDLotteryBase.level: this.level = v; break;
			case E_CDLotteryBase.unlockid: this.unlockid = v; break;
			case E_CDLotteryBase.activityID: this.activityID = v; break;
			case E_CDLotteryBase.maxDropIndex: this.maxDropIndex = v; break;
			case E_CDLotteryBase.costType: this.costType = v; break;
			case E_CDLotteryBase.costItem: this.costItem = v; break;
			case E_CDLotteryBase.costNum: this.costNum = v; break;
			case E_CDLotteryBase.showType: this.showType = v; break;
			case E_CDLotteryBase.name: this.name = v; break;
			case E_CDLotteryBase.desc: this.desc = v; break;
			case E_CDLotteryBase.levelName: this.levelName = v; break;
			case E_CDLotteryBase.background: this.background = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDLotteryBase> = new HashMap<number, CDLotteryBase>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDLotteryBase[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDLotteryBase();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].lotteryType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].freeTimes = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].limitid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].watchAd = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].order = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].level = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].unlockid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].activityID = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].maxDropIndex = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costItem = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].costNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].showType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].levelName = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].background = byte.readString();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDLotteryBase{
		return this.datas ? this.datas.get(id) : null;
	}
}
